<template>
  <div class="height100 flex flex_d bg_fff" :class="is_close?'close_nav':''">
    <!-- <div class="common_tt flex_ac">
      <a href="javascript:;" @click="$router.go(-1);" class="back"><img src="@/assets/back.png" alt=""></a>
      <div class="title pad_lr20">题库模板</div>
    </div> -->
    <div class="flex1 flex flex_d">
      <!-- <div class="pro_nav height100">
        <Pronav2 />
        <img src="@/assets/close.png" @click="is_close=!is_close" class="close" alt="">
      </div> -->
      <div class="flex_s pad_lr30">
        <div class="f18 pad_t20 pad_b10"><b>题库模板</b></div>
        <el-form :model="queryParams" ref="queryForm"  label-width="104px">
          <el-row class="flex flex_w">
            <FormItem label="模板名称" class="bg_form_item" type="input" :form="queryParams" @keyenter="handleQuery" prop="title" clearable />
            <div class="search_btns">
              <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
            </div>
            <div class="margin_a">

              <el-button type="primary" @click="$router.push('/answer/addanswer?id=')" v-if="have_auth('/answer/index/add')">新增题库</el-button>
            </div>
          </el-row>
        </el-form>
      </div>
      <div class="flex1 page_div">
        <el-scrollbar class="page_div_scroll">
          <el-table v-loading="loading" :data="list">
            <el-table-column label="序号" align="left" prop="id" width="80" />
            <el-table-column label="模板名称" align="left" prop="title" :show-overflow-tooltip="true" />
            <!-- <el-table-column label="模板题目数" align="left" prop="subject_num" width="200px" :show-overflow-tooltip="true" /> -->
            <!-- <el-table-column label="应用次数" align="left" prop="use_num" width="200px" :show-overflow-tooltip="true" /> -->

            <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220px" fixed="right">
              <template slot-scope="scope">
                <el-button size="mini" type="text" @click="handleEdit(scope.row)" v-if="have_auth('/answer/index/edit')">修改</el-button>
                <el-button size="mini" type="text" @click="handleDelete(scope.row)" v-if="have_auth('/answer/index/del')">删除</el-button>
                <el-button size="mini" type="text" @click="handleCopy(scope.row)" v-if="have_auth('/answer/index/copy')">复制</el-button>
                <el-button size="mini" type="text" @click="handleDetail(scope.row)"  v-if="have_auth('/answer/answerlist')">编辑题库</el-button>
              </template>
            </el-table-column>
            -->

            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="400px" fixed="right">
              <template slot-scope="scope">
                <el-button size="mini" type="text" @click="handleEdit(scope.row)" v-if="have_auth('/answer/index/edit')">修改</el-button>
                <el-button size="mini" type="text" @click="handleDelete(scope.row)" v-if="have_auth('/answer/index/del')">删除</el-button>
                <el-button size="mini" type="text" @click="handleCopy(scope.row)" v-if="have_auth('/answer/index/copy')">复制</el-button>
                <el-button size="mini" type="text" @click="handleDetail(scope.row)"  v-if="have_auth('/answer/answerlist')">编辑题库</el-button>
                <el-button size="mini" type="text" @click="handleCate(scope.row)"  v-if="have_auth('/answer/index/zb')">设置指标</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.page"
            :limit.sync="queryParams.page_size"
            @pagination="getList"
          />

        </el-scrollbar>

      </div>
    </div>
    <cate ref="cate" />
  </div>
</template>

<script>
import cate from "./cate.vue";
export default {
  name: 'needCache',
  components: {cate},
  data () {
    return {
      loading:true,
      is_ajax:false,
      show_filter:true,
      is_close:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      total: 0,
      // 定时任务表格数据
      list: [],
      // 查询参数
      queryParams: {
        page: 1,
        page_size: 10,
        title: undefined,
        type: undefined,
        status: undefined
      },
      statusOptions: [{label:'启用',value:'0'},{label:'停用',value:'1'}],
      openOptions: [{label:'当前页面打开',value:0},{label:'新页面打开',value:1}],
      open:false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        man: [
          { required: true, message: "客户经理不能为空", trigger: "blur" }
        ]
      },
    }
  },
  activated() {
    this.getList();
  },
  methods:{
    handleCate(row){
      this.$refs.cate.init(row.id)
    },
    handleCopy(row){
      const ids = row.id || this.ids;
      const _this=this;
      this.$confirm('是否确认复制?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          _this.axios.post("/api/QuestionnaireVersion/copy_questionnaire", {id:ids}).then(function(res) {
            if(res){
              _this.tip_show('操作成功','success')
              _this.getList();
            }
          }).catch(function(error) {
            console.log(error);
          })
        })
    },
    handleEdit(row){
      window.edit_answer=row;
      this.$router.push({ //核心语句
        path: '/answer/addanswer?id='+row.id,
      })
    },
    handleDetail(row){
      this.$router.push({ //核心语句
        path: '/answer/answerlist?id='+row.id+'&title='+row.title,
      })
    },


    /** 查询定时任务列表 */
    getList() {
      const _this=this;
      this.loading = true;
      _this.axios.get("/api/QuestionnaireVersion/index", {params:this.queryParams}).then(function(res) {
        if(res){
          _this.list = res.message.data;
          _this.total = res.message.total;
          _this.loading = false;
        }
      }).catch(function(error) {
        console.log(error);
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams= {
        page: 1,
        page_size: 10,
        title: undefined,
        type: undefined,
        status: undefined
      }
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const _this=this;
      this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          _this.axios.post("/api/QuestionnaireVersion/questionnaire_delete", {id:ids}).then(function(res) {
            if(res){
              _this.tip_show('操作成功','success')
              _this.getList();
            }
          }).catch(function(error) {
            console.log(error);
          })
        })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.open_filter{font-size: 14px;}
.open_filter.active i{transform: rotate(180deg);}
</style>
